const config = require("../config/config");
const responseMiddleware = (req, res, next) => {
    // 定义一个统一的响应函数
    res.success = (data, total, code = config.code.success, message = "请求成功") => {
        res.status(code).json({
            code,
            message,
            data,
            total
        });
    };

    res.error = (message = "请求失败", code = config.code.commonError, data = null) => {
        res.status(code).json({
            code,
            message,
            data,
        });
    };
    next();
};

exports.responseMiddleware = responseMiddleware;